﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Text.RegularExpressions;

namespace PurchaseManager
{
    // public class DataStore
    // DataStore 역할을 MainWindow에서 처리
    public partial class MainWindow
    {
        public DBManager _dbManager = new DBManager();

        /////  전역으로 데이터를 가져가지 않고 DB에서 따로 가져가는 것으로 처리
        /////  복사가 되지 않고 참조가 됨

        #region - Reload : 데이터가 변경되면 화면을 자동으로 변경해주는 부분

        public void ReloadCompanyList()
        {
        }

        public void ReloadCategoryList()
        {
        }

        public void ReloadProductList()
        {
        }

        public void ReloadSellItemList()
        {
        }

        public void ReloadPurchaseItemList()
        {
        }

        #endregion - Reload

        #region GetDataStore
        public ObservableCollection<Category> GetCategoryList()
        {
            return _dbManager.RetrieveCategoryList();
        }

        public ObservableCollection<Company> GetCompanyList()
        {
            return _dbManager.RetrieveCompanyList();
        }

        public ObservableCollection<Product> GetProductList()
        {
            return _dbManager.RetrieveProductList();
        }

        public ObservableCollection<Item> GetSellItemList()
        {
            return _dbManager.RetrieveSellItemList();
        }

        public ObservableCollection<Item> GetPurchaseItemList()
        {
            return _dbManager.RetrievePurchaseItemList();
        }

        public ObservableCollection<Product> GetProductItemListByParentId(int id)
        {
            ObservableCollection<Product> filterList = new ObservableCollection<Product>();

            ObservableCollection<Product> itemList = _dbManager.RetrieveProductList();
            var query = from Product item in itemList orderby item.ParentId select item;

            foreach (Product pItem in query)
            {
                filterList.Add(pItem);
            }

            // return TransformWBSList(filterList);
            return filterList;
        }

        public ObservableCollection<Item> GetSellItemListByProductId(int id)
        {
            ObservableCollection<Item> filterList = new ObservableCollection<Item>();

            ObservableCollection<Item> itemList = _dbManager.RetrieveSellItemList();
            var query = from Item item in itemList orderby item.ProductId select item;

            foreach (Item wItem in query)
            {
                filterList.Add(wItem);
            }

            // return TransformWBSList(filterList);
            return filterList;
        }

        public ObservableCollection<Item> GetPurchaseItemListByProductId(int id)
        {
            ObservableCollection<Item> filterList = new ObservableCollection<Item>();

            ObservableCollection<Item> itemList = _dbManager.RetrievePurchaseItemList();
            var query = from Item item in itemList orderby item.ProductId select item;

            foreach (Item wItem in query)
            {
                filterList.Add(wItem);
            }

            // return TransformWBSList(filterList);
            return filterList;
        }
        
        #endregion -GetDataStore

        #region Remove Data
        public void RemoveCompanyList(List<Company> companyList)
        {
            _dbManager.DeleteCompanyList(ref companyList);
            ReloadCompanyList();
        }

        public void RemoveCategoriesList(List<Category> cateList)
        {
            _dbManager.DeleteCategoryList(ref cateList);
            ReloadCategoryList();
        }

        public void RemoveProductList(List<Product> productList)
        {
            _dbManager.DeleteProductList(ref productList);
            ReloadProductList();
        }

        public void RemoveSellItemList(List<Item> itemList)
        {
            _dbManager.DeleteSellItemList(ref itemList);
            ReloadSellItemList();
        }

        public void RemovePurchaseItemList(List<Item> itemList)
        {
            _dbManager.DeletePurchaseItemList(ref itemList);
            ReloadPurchaseItemList();
        }

        public void DeleteCategoryAll()
        {
            _dbManager.DeleteAllCategories();
            ReloadCategoryList();
        }

        public void DeleteCompanyAll()
        {
            _dbManager.DeleteAllCompanies();
            ReloadCompanyList();
        }

        public void DeleteProductAll()
        {
            _dbManager.DeleteAllProducts();
            ReloadProductList();
        }

        public void DeleteSellItemAll()
        {
            _dbManager.DeleteAllSellItems();
            ReloadSellItemList();
        }

        public void DeletePurchaseItemAll()
        {
            _dbManager.DeleteAllPurchaseItems();
            ReloadPurchaseItemList();
        }

        #endregion - Remove Data

        #region - Find
        public Category FindCategory(int id, ObservableCollection<Category> itemList)
        {
            var query = from Category item in itemList where item.Id == id select item;

            if (query != null && query.ToList<Category>().Count > 0)
            {
                return query.ToList<Category>()[0];
            }

            return null;
        }

        public Category FindCategory(string name, ObservableCollection<Category> itemList)
        {
            var query = from Category item in itemList where item.Name == name select item;

            if (query != null && query.ToList<Category>().Count > 0)
            {
                return query.ToList<Category>()[0];
            }

            return null;
        }

        public Company FindCompany(int id, ObservableCollection<Company> itemList)
        {
            var query = from Company item in itemList where item.Id == id select item;

            if (query != null && query.ToList<Company>().Count > 0)
            {
                return query.ToList<Company>()[0];
            }

            return null;
        }

        public Company FindCompany(string name, ObservableCollection<Company> itemList)
        {
            var query = from Company item in itemList where item.Name == name select item;

            if (query != null && query.ToList<Company>().Count > 0)
            {
                return query.ToList<Company>()[0];
            }

            return null;
        }

        public Product FindProduct(int id, ObservableCollection<Product> itemList)
        {
            var query = from Product item in itemList where item.Id == id select item;

            if (query != null && query.ToList<Product>().Count > 0)
            {
                return query.ToList<Product>()[0];
            }

            return null;
        }

        // Sell, Purchase의 구분은 뒤의 itemList로 한다.
        public Item FindItem(int id, ObservableCollection<Item> itemList)
        {
            var query = from Item item in itemList where item.Id == id select item;

            if (query != null && query.ToList<Item>().Count > 0)
            {
                return query.ToList<Item>()[0];
            }

            return null;
        }

        #endregion - Find

        #region Update(Insert or Replace or Delete) Data
        public void UpdateCategoryList(ObservableCollection<Category> categoryList)
        {
            ObservableCollection<Category> allCategoryList = GetCategoryList();

            List<Category> addList = new List<Category>();
            List<Category> updateList = new List<Category>();
            List<Category> deleteList = new List<Category>();

            foreach (Category cItem in categoryList)
            {
                if (string.IsNullOrEmpty(cItem.Name)) continue;

                Category find = FindCategory(cItem.Name, allCategoryList);

                if (find != null)
                {
                    if (!find.Compare(cItem))
                    {
                        updateList.Add(cItem);
                    }
                }
                else
                {
                    addList.Add(cItem);
                }
            }

            // 삭제 된 것을 찾는다.
            foreach (Category cItem in allCategoryList)
            {
                Category findItem = FindCategory(cItem.Id, categoryList);

                if (findItem == null)
                {
                    deleteList.Add(cItem);
                }
            }

            _dbManager.UpdateCategoryList(ref updateList);
            _dbManager.InsertCategoryList(ref addList);
            _dbManager.DeleteCategoryList(ref deleteList);

            ReloadCategoryList();
        }

        public void UpdateCompanyList(ObservableCollection<Company> companyList)
        {
            ObservableCollection<Company> allCompanyList = GetCompanyList();

            List<Company> addList = new List<Company>();
            List<Company> updateList = new List<Company>();
            List<Company> deleteList = new List<Company>();

            foreach (Company cItem in companyList)
            {
                if (string.IsNullOrEmpty(cItem.Name)) continue;

                Company find = FindCompany(cItem.Name, allCompanyList);

                if (find != null)
                {
                    if (!find.Compare(cItem))
                    {
                        updateList.Add(cItem);
                    }
                }
                else
                {
                    addList.Add(cItem);
                }
            }

            // 삭제 된 것을 찾는다.
            foreach (Company cItem in allCompanyList)
            {
                Company findItem = FindCompany(cItem.Id, companyList);

                if (findItem == null)
                {
                    deleteList.Add(cItem);
                }
            }

            _dbManager.UpdateCompanyList(ref updateList);
            _dbManager.InsertCompanyList(ref addList);
            _dbManager.DeleteCompanyList(ref deleteList);

            ReloadCompanyList();
        }

        public void UpdateProductList(ObservableCollection<Product> productList)
        {
            ObservableCollection<Product> allProductList = GetProductList();

            List<Product> addList = new List<Product>();
            List<Product> updateList = new List<Product>();
            List<Product> deleteList = new List<Product>();

            foreach (Product item in productList)
            {
                if (string.IsNullOrEmpty(item.ItemName)) continue;

                Product find = FindProduct(item.Id, allProductList);

                if (find != null)
                {
                    if (!find.Compare(item))
                    {
                        updateList.Add(item);
                    }
                }
                else
                {
                    addList.Add(item);
                }
            }

            // 삭제 된 것을 찾는다.
            foreach (Product pItem in allProductList)
            {
                Product findItem = FindProduct(pItem.Id, productList);

                if (findItem == null)
                {
                    deleteList.Add(pItem);
                }
            }

            _dbManager.UpdateProductList(ref updateList);
            _dbManager.InsertProductList(ref addList);
            _dbManager.DeleteProductList(ref deleteList);

            ReloadProductList();
        }

        public void UpdateSellItemList(ObservableCollection<Item> itemList)
        {
            ObservableCollection<Item> allItemList = GetSellItemList();

            List<Item> addList = new List<Item>();
            List<Item> updateList = new List<Item>();
            List<Item> deleteList = new List<Item>();

            foreach (Item item in itemList)
            {
                Item find = FindItem(item.Id, allItemList);

                if (find != null)
                {
                    if (!find.Compare(item))
                    {
                        updateList.Add(item);
                    }
                }
                else
                {
                    addList.Add(item);
                }
            }

            // 삭제 된 것을 찾는다.
            foreach (Item cItem in allItemList)
            {
                Item findItem = FindItem(cItem.Id, itemList);

                if (findItem == null)
                {
                    deleteList.Add(cItem);
                }
            }

            _dbManager.UpdateItemList(ref updateList, "SellItem");
            _dbManager.InsertSellItemList(ref addList);
            _dbManager.DeleteSellItemList(ref deleteList);

            ReloadSellItemList();
        }

        public void UpdatePurchaseItemList(ObservableCollection<Item> itemList)
        {
            ObservableCollection<Item> allItemList = GetPurchaseItemList();

            List<Item> addList = new List<Item>();
            List<Item> updateList = new List<Item>();
            List<Item> deleteList = new List<Item>();

            foreach (Item item in itemList)
            {
                Item find = FindItem(item.Id, allItemList);

                if (find != null)
                {
                    if (!find.Compare(item))
                    {
                        updateList.Add(item);
                    }
                }
                else
                {
                    addList.Add(item);
                }
            }

            // 삭제 된 것을 찾는다.
            foreach (Item cItem in allItemList)
            {
                Item findItem = FindItem(cItem.Id, itemList);

                if (findItem == null)
                {
                    deleteList.Add(cItem);
                }
            }

            _dbManager.UpdateItemList(ref updateList, "PurchaseItem");
            _dbManager.InsertPurchaseItemList(ref addList);
            _dbManager.DeletePurchaseItemList(ref deleteList);

            ReloadPurchaseItemList();
        }

        #endregion  - Update

        //// 개별 수정
        //public void UpdateOperator(Operator oItem)
        //{
        //    List<Operator> updateList = new List<Operator>();

        //    //세부프로젝트 변환
        //    Manager mngr = FindManager(oItem.o_Manager_combo);
        //    if (mngr != null)
        //    {
        //        oItem.o_M_id_fk = mngr.m_ID;
        //    }

        //    //신청자 변환
        //    Researcher res = FindResearcher(oItem.o_Researcher_combo);
        //    if (res != null)
        //    {
        //        oItem.o_R_id_fk = res.r_ID;
        //    }

        //    //구매 조건 변환
        //    oItem.o_Request_condition = (int)StringToRequestCondition(oItem.o_Request_condition_combo);

        //    //구매 요구 일자 변환
        //    oItem.o_Puchase_request_date_value = oItem.o_Puchase_request_dt.Ticks;

        //    // 계약 날짜 변환
        //    oItem.o_Contract_date_value = oItem.o_Contract_dt.Ticks;
        //    //oItem.o_Operation_date_value = oItem.o_Operation_dt.Ticks;

        //    // 화폐 단위 변환
        //    oItem.o_Currency_type = (int)StringToCurrency(oItem.o_Currency_type_combo);

        //    // 진행 상태 변환
        //    oItem.o_Current_state = (int)StringToState(oItem.o_Current_status_combo);

        //    Operator findItem = FindOperator(oItem.o_ID);

        //    if (findItem != null)
        //    {
        //        updateList.Add(oItem);
        //    }

        //    _dbManager.UpdateOperatorList(ref updateList);

        //    ReloadOperatorList();
        //}


        //#region - Find
        ///// <summary>
        ///// Linq를 사용하여 탐색을 하도록 수정
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //public Department FindDepartment(int id)
        //{
        //    ObservableCollection<Department> itemList = _dbManager.RetrieveDepartmentList();

        //    var query = from Department item in itemList where item.dep_ID == id select item;

        //    if (query != null && query.ToList<Department>().Count > 0)
        //    {
        //        return query.ToList<Department>()[0];
        //    }

        //    return null;

        //    // return query.ToList<Department>(); List 형태로 넘길때는 아래와 같이 처리
        //}

        //public Department FindDepartment(string name)
        //{
        //    ObservableCollection<Department> itemList = _dbManager.RetrieveDepartmentList();

        //    var query = from Department item in itemList where item.dep_Name == name select item;

        //    if (query != null && query.ToList<Department>().Count > 0)
        //    {
        //        return query.ToList<Department>()[0];
        //    }

        //    return null;
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="id">부서 id</param>
        ///// <param name="itemList">찾을 datasource</param>
        ///// <returns></returns>
        //public Department FindDepartment(int id, List<Department> itemList)
        //{
        //    var query = from Department item in itemList where item.dep_ID == id select item;

        //    if (query != null && query.ToList<Department>().Count > 0)
        //    {
        //        return query.ToList<Department>()[0];
        //    }

        //    return null;
        //}

        ///// <summary>
        ///// 
        ///// </summary>
        ///// <param name="name">부서 이름</param>
        ///// <param name="itemList">찾을 datasource</param>
        ///// <returns></returns>
        //public Department FindDepartment(string name, List<Department> itemList)
        //{
        //    var query = from Department item in itemList where item.dep_Name == name select item;

        //    if (query != null && query.ToList<Department>().Count > 0)
        //    {
        //        return query.ToList<Department>()[0];
        //    }

        //    return null;
        //}

        //public Team FindTeam(int id)
        //{
        //    ObservableCollection<Team> itemList = _dbManager.RetrieveTeamList();

        //    var query = from Team item in itemList where item.t_ID == id select item;

        //    if (query != null && query.ToList<Team>().Count > 0)
        //    {
        //        return query.ToList<Team>()[0];
        //    }

        //    return null;
        //}

        //public Team FindTeam(string name)
        //{
        //    ObservableCollection<Team> itemList = _dbManager.RetrieveTeamList();

        //    var query = from Team item in itemList where item.t_Name == name select item;

        //    if (query != null && query.ToList<Team>().Count > 0)
        //    {
        //        return query.ToList<Team>()[0];
        //    }

        //    return null;
        //}

        //public Team FindTeam(int id, List<Team> itemList)
        //{
        //    var query = from Team item in itemList where item.t_ID == id select item;

        //    if (query != null && query.ToList<Team>().Count > 0)
        //    {
        //        return query.ToList<Team>()[0];
        //    }

        //    return null;
        //}

        //public Team FindTeam(string name, List<Team> itemList)
        //{
        //    var query = from Team item in itemList where item.t_Name == name select item;

        //    if (query != null && query.ToList<Team>().Count > 0)
        //    {
        //        return query.ToList<Team>()[0];
        //    }

        //    return null;
        //}

        //public Category FindCategory(int id)
        //{
        //    ObservableCollection<Category> itemList = _dbManager.RetrieveCategoryList();

        //    var query = from Category item in itemList where item.c_ID == id select item;

        //    if (query != null && query.ToList<Category>().Count > 0)
        //    {
        //        return query.ToList<Category>()[0];
        //    }

        //    return null;
        //}

        //public Category FindCategory(string name)
        //{
        //    ObservableCollection<Category> itemList = _dbManager.RetrieveCategoryList();

        //    var query = from Category item in itemList where item.c_Name == name select item;

        //    if (query != null && query.ToList<Category>().Count > 0)
        //    {
        //        return query.ToList<Category>()[0];
        //    }

        //    return null;
        //}

        //public Category FindCategory(int id, List<Category> itemList)
        //{
        //    var query = from Category item in itemList where item.c_ID == id select item;

        //    if (query != null && query.ToList<Category>().Count > 0)
        //    {
        //        return query.ToList<Category>()[0];
        //    }

        //    return null;
        //}

        //public Category FindCategory(string name, List<Category> itemList)
        //{
        //    var query = from Category item in itemList where item.c_Name == name select item;

        //    if (query != null && query.ToList<Category>().Count > 0)
        //    {
        //        return query.ToList<Category>()[0];
        //    }

        //    return null;
        //}

        //public WBS FindWBS(int id)
        //{
        //    ObservableCollection<WBS> itemList = _dbManager.RetrieveWBSList();

        //    var query = from WBS item in itemList where item.wbs_ID == id select item;

        //    if (query != null && query.ToList<WBS>().Count > 0)
        //    {
        //        return query.ToList<WBS>()[0];
        //    }

        //    return null;
        //}

        //public WBS FindWBS(string name)
        //{
        //    ObservableCollection<WBS> itemList = _dbManager.RetrieveWBSList();

        //    var query = from WBS item in itemList where item.wbs_Name == name select item;

        //    if (query != null && query.ToList<WBS>().Count > 0)
        //    {
        //        return query.ToList<WBS>()[0];
        //    }

        //    return null;
        //}

        //public WBS FindWBSLevel(string level)
        //{
        //    ObservableCollection<WBS> itemList = _dbManager.RetrieveWBSList();

        //    var query = from WBS item in itemList where item.wbs_Level == level select item;

        //    if (query != null && query.ToList<WBS>().Count > 0)
        //    {
        //        return query.ToList<WBS>()[0];
        //    }

        //    return null;
        //}

        //public WBS FindWBS(int id, List<WBS> itemList)
        //{
        //    var query = from WBS item in itemList where item.wbs_ID == id select item;

        //    if (query != null && query.ToList<WBS>().Count > 0)
        //    {
        //        return query.ToList<WBS>()[0];
        //    }

        //    return null;
        //}

        //public WBS FindWBS(string name, List<WBS> itemList)
        //{
        //    var query = from WBS item in itemList where item.wbs_Name == name select item;

        //    if (query != null && query.ToList<WBS>().Count > 0)
        //    {
        //        return query.ToList<WBS>()[0];
        //    }

        //    return null;
        //}

        //public WBS FindWBSLevel(string level, List<WBS> itemList)
        //{
        //    var query = from WBS item in itemList where item.wbs_Level == level select item;

        //    if (query != null && query.ToList<WBS>().Count > 0)
        //    {
        //        return query.ToList<WBS>()[0];
        //    }

        //    return null;
        //}

        //public Researcher FindResearcher(int id)
        //{
        //    ObservableCollection<Researcher> itemList = _dbManager.RetrieveResearcherList();

        //    var query = from Researcher item in itemList where item.r_ID == id select item;

        //    if (query != null && query.ToList<Researcher>().Count > 0)
        //    {
        //        return query.ToList<Researcher>()[0];
        //    }

        //    return null;
        //}

        //public Researcher FindResearcher(string name)
        //{
        //    ObservableCollection<Researcher> itemList = _dbManager.RetrieveResearcherList();

        //    var query = from Researcher item in itemList where item.r_Name == name select item;

        //    if (query != null && query.ToList<Researcher>().Count > 0)
        //    {
        //        return query.ToList<Researcher>()[0];
        //    }

        //    return null;
        //}

        //public Researcher FindResearcher(int id, List<Researcher> itemList)
        //{
        //    var query = from Researcher item in itemList where item.r_ID == id select item;

        //    if (query != null && query.ToList<Researcher>().Count > 0)
        //    {
        //        return query.ToList<Researcher>()[0];
        //    }

        //    return null;
        //}

        //public Researcher FindResearcher(string name, List<Researcher> itemList)
        //{
        //    var query = from Researcher item in itemList where item.r_Name == name select item;

        //    if (query != null && query.ToList<Researcher>().Count > 0)
        //    {
        //        return query.ToList<Researcher>()[0];
        //    }

        //    return null;
        //}

        //public Project FindProject(int id)
        //{
        //    ObservableCollection<Project> itemList = _dbManager.RetrieveProjectList();

        //    var query = from Project item in itemList where item.p_ID == id select item;

        //    if (query != null && query.ToList<Project>().Count > 0)
        //    {
        //        return query.ToList<Project>()[0];
        //    }

        //    return null;
        //}

        //public Project FindProject(string name)
        //{
        //    ObservableCollection<Project> itemList = _dbManager.RetrieveProjectList();

        //    var query = from Project item in itemList where item.p_Name == name select item;

        //    if (query != null && query.ToList<Project>().Count > 0)
        //    {
        //        return query.ToList<Project>()[0];
        //    }

        //    return null;
        //}

        //public Project FindProject(int id, List<Project> itemList)
        //{
        //    var query = from Project item in itemList where item.p_ID == id select item;

        //    if (query != null && query.ToList<Project>().Count > 0)
        //    {
        //        return query.ToList<Project>()[0];
        //    }

        //    return null;
        //}

        //public Project FindProject(string name, List<Project> itemList)
        //{
        //    var query = from Project item in itemList where item.p_Name == name select item;

        //    if (query != null && query.ToList<Project>().Count > 0)
        //    {
        //        return query.ToList<Project>()[0];
        //    }

        //    return null;
        //}

        //public Manager FindManager(int id)
        //{
        //    ObservableCollection<Manager> itemList = _dbManager.RetrieveManagerList();

        //    var query = from Manager item in itemList where item.m_ID == id select item;

        //    if (query != null && query.ToList<Manager>().Count > 0)
        //    {
        //        return query.ToList<Manager>()[0];
        //    }

        //    return null;
        //}

        //public Manager FindManager(string name)
        //{
        //    ObservableCollection<Manager> itemList = _dbManager.RetrieveManagerList();

        //    var query = from Manager item in itemList where item.m_Name == name select item;

        //    if (query != null && query.ToList<Manager>().Count > 0)
        //    {
        //        return query.ToList<Manager>()[0];
        //    }

        //    return null;
        //}

        //public Manager FindManager(int id, List<Manager> itemList)
        //{
        //    var query = from Manager item in itemList where item.m_ID == id select item;

        //    if (query != null && query.ToList<Manager>().Count > 0)
        //    {
        //        return query.ToList<Manager>()[0];
        //    }

        //    return null;
        //}

        //public Manager FindManager(string name, List<Manager> itemList)
        //{
        //    var query = from Manager item in itemList where item.m_Name == name select item;

        //    if (query != null && query.ToList<Manager>().Count > 0)
        //    {
        //        return query.ToList<Manager>()[0];
        //    }

        //    return null;
        //}

        //public Operator FindOperator(int id)
        //{
        //    ObservableCollection<Operator> itemList = _dbManager.RetrieveOperatorList();

        //    var query = from Operator item in itemList where item.o_ID == id select item;

        //    if (query != null && query.ToList<Operator>().Count > 0)
        //    {
        //        return query.ToList<Operator>()[0];
        //    }

        //    return null;
        //}

        //public Operator FindOperator(int id, List<Operator> itemList)
        //{
        //    var query = from Operator item in itemList where item.o_ID == id select item;

        //    if (query != null && query.ToList<Operator>().Count > 0)
        //    {
        //        return query.ToList<Operator>()[0];
        //    }

        //    return null;
        //}

        //public Operator FindOperator(string name)
        //{
        //    ObservableCollection<Operator> itemList = _dbManager.RetrieveOperatorList();

        //    var query = from Operator item in itemList where item.o_Name == name select item;

        //    if (query != null && query.ToList<Operator>().Count > 0)
        //    {
        //        return query.ToList<Operator>()[0];
        //    }

        //    return null;
        //}

        //public Operator FindOperator(string name, List<Operator> itemList)
        //{
        //    var query = from Operator item in itemList where item.o_Name == name select item;

        //    if (query != null && query.ToList<Operator>().Count > 0)
        //    {
        //        return query.ToList<Operator>()[0];
        //    }

        //    return null;
        //}
        //#endregion - Find

        //#region - Filter

        ///// <summary>
        /////  OperatorList를 Manager ID를 필터로 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <param name="managerId">Manager ID</param>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterManager(int managerId)
        //{
        //    ObservableCollection<Operator> itemList = _dbManager.RetrieveOperatorList();

        //    var query = from Operator item in itemList where item.o_M_id_fk == managerId select item;

        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();

        //    foreach (Operator oItem in query)
        //    {
        //        filterList.Add(oItem);
        //    }
            
        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        ///// OperatorList를 Manager ID를 필터로 사용하여 가져온다.
        ///// </summary>
        ///// <param name="managerId"></param>
        ///// <param name="itemList">Data Source</param>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterManager(int managerId, List<Operator> itemList)
        //{
        //    var query = from Operator item in itemList where item.o_M_id_fk == managerId select item;

        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();

        //    foreach (Operator oItem in query)
        //    {
        //        filterList.Add(oItem);
        //    }

        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        ///// OperatorList를 Project ID를 필터로 사용하여 가져온다.
        ///// </summary>
        ///// <param name="projectId"></param>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterProject(int projectId)
        //{
        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();

        //    // Project에 속한 Manager를 가져온다.
        //    ObservableCollection<Manager> mgrList = GetManagerListFilterProject(projectId);

        //    foreach (Manager mItem in mgrList)
        //    {
        //        ObservableCollection<Operator> opList = GetOperatorListFilterManager(mItem.m_ID);

        //        foreach (Operator oItem in opList)
        //        {
        //            filterList.Add(oItem);
        //        }
        //    }

        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        ///// OperatorList를 Project ID를 필터로 사용하여 가져온다.
        ///// </summary>
        ///// <param name="managerId"></param>
        ///// <param name="itemList">Data Source</param>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterProject(int projectId, List<Operator> itemList)
        //{
        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();

        //    // Project에 속한 Manager를 가져온다.
        //    ObservableCollection<Manager> mgrList = GetManagerListFilterProject(projectId);

        //    foreach (Manager mItem in mgrList)
        //    {
        //        ObservableCollection<Operator> opList = GetOperatorListFilterManager(mItem.m_ID, itemList);

        //        foreach (Operator oItem in opList)
        //        {
        //            filterList.Add(oItem);
        //        }
        //    }

        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        /////  OperatorList를 Contract_amount가 0인것을 필터로 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterNoContract()
        //{
        //    ObservableCollection<Operator> itemList = _dbManager.RetrieveOperatorList();

        //    var query = from Operator item in itemList where item.o_Contract_amount <= 0 select item;

        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();

        //    foreach (Operator oItem in query)
        //    {
        //        filterList.Add(oItem);
        //    }

        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        ///// OperatorList를 Contract_amount가 0인것을 필터로 사용하여 가져온다
        ///// </summary>
        ///// <param name="itemList"> Data Source </param>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterNoContract(ObservableCollection<Operator> itemList)
        //{
        //    var query = from Operator item in itemList where item.o_Contract_amount <= 0 select item;

        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();

        //    foreach (Operator oItem in query)
        //    {
        //        filterList.Add(oItem);
        //    }

        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        ///// OperatorList를 department id로 가져온다.
        ///// </summary>
        ///// <param name="depid">department id</param>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterDepartment(int depid)
        //{
        //    ObservableCollection<Operator> itemList = _dbManager.RetrieveOperatorList();
        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();
        //    ObservableCollection<Team> teamList = GetTeamListFilterDepartment(depid);

        //    foreach (Team tItem in teamList)
        //    {
        //        ObservableCollection<Researcher> researcherList = GetResearcherListFilterTeam(tItem.t_ID);

        //        foreach (Researcher rItem in researcherList)
        //        {
        //            var query = from Operator item in itemList where item.o_R_id_fk == rItem.r_ID select item;

        //            foreach (Operator oItem in query)
        //            {
        //                filterList.Add(oItem);
        //            }
        //        }
        //    }

        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        ///// OperatorList를 department id로 가져온다.
        ///// </summary>
        ///// <param name="depid">department id</param>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterDepartment(int depid, List<Operator> itemList)
        //{
        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();
        //    ObservableCollection<Team> teamList = GetTeamListFilterDepartment(depid);

        //    foreach (Team tItem in teamList)
        //    {
        //        ObservableCollection<Researcher> researcherList = GetResearcherListFilterTeam(tItem.t_ID);

        //        foreach (Researcher rItem in researcherList)
        //        {
        //            var query = from Operator item in itemList where item.o_R_id_fk == rItem.r_ID select item;

        //            foreach (Operator oItem in query)
        //            {
        //                filterList.Add(oItem);
        //            }
        //        }
        //    }

        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        ///// OperatorList를 team id로 가져온다.
        ///// </summary>
        ///// <param name="tid"> team id</param>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterTeam(int tid)
        //{
        //    ObservableCollection<Operator> itemList = _dbManager.RetrieveOperatorList();
        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();

        //    ObservableCollection<Manager> mgrList = GetManagerListFilterTeam(tid);

        //    foreach (Manager mItem in mgrList)
        //    {
        //        var query = from Operator item in itemList where item.o_M_id_fk == mItem.m_ID select item;

        //        foreach (Operator oItem in query)
        //        {
        //            filterList.Add(oItem);
        //        }
        //    }

        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        ///// OperatorList를 team id로 가져온다.
        ///// </summary>
        ///// <param name="tid"> team id</param>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterTeam(int tid, List<Operator> itemList)
        //{
        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();

        //    ObservableCollection<Manager> mgrList = GetManagerListFilterTeam(tid);

        //    foreach (Manager mItem in mgrList)
        //    {
        //        var query = from Operator item in itemList where item.o_M_id_fk == mItem.m_ID select item;

        //        foreach (Operator oItem in query)
        //        {
        //            filterList.Add(oItem);
        //        }
        //    }

        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        ///// ManagerList를 WBS ID를 필터로 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <param name="id">WBS ID</param>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterWBS(int id)
        //{
        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();
        //    ObservableCollection<Manager> mgrList = GetManagerListFilterWBS(id);

        //    foreach (Manager mItem in mgrList)
        //    {
        //        ObservableCollection<Operator> opList = GetOperatorListFilterManager(mItem.m_ID);

        //        foreach (Operator oItem in opList)
        //        {
        //            filterList.Add(oItem);
        //        }
        //    }

        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        ///// OperatorList를 WBS ID를 필터로 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <param name="id">WBS ID</param>
        ///// <returns></returns>
        //public ObservableCollection<Operator> GetOperatorListFilterWBS(List<WBS> wbsList)
        //{
        //    ObservableCollection<Operator> itemList = _dbManager.RetrieveOperatorList();
        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();

        //    foreach (WBS wItem in wbsList)
        //    {
        //        ObservableCollection<Manager> mgrList = GetManagerListFilterWBS(wItem.wbs_ID);

        //        foreach (Manager mItem in mgrList)
        //        {
        //            ObservableCollection<Operator> opList = GetOperatorListFilterManager(mItem.m_ID);

        //            foreach (Operator oItem in opList)
        //            {
        //                filterList.Add(oItem);
        //            }
        //        }
        //    }

        //    return TransformOperatorList(filterList);

        //}

        ///// <summary>
        ///// ManagerList를 부서 ID를 필터로 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //public ObservableCollection<Manager> GetManagerListFilterDepartment(int id)
        //{
        //    ObservableCollection<Manager> filterList = new ObservableCollection<Manager>();
            
        //    // Department 에 속한 team List를 가져온다.
        //    ObservableCollection<Team> teamList = GetTeamListFilterDepartment(id);

        //    foreach (Team tItem in teamList)
        //    {
        //        // team에 속한 wbs list를 가져온다.
        //        ObservableCollection<WBS> wbsList = GetWBSListFilterTeam(tItem.t_ID);

        //        foreach (WBS wItem in wbsList)
        //        {
        //            // 해당 wbs에 속한 Project List를 가져온다.
        //            ObservableCollection<Project> projectList = GetProjectListFilterWBS(wItem.wbs_ID);

        //            foreach (Project pItem in projectList)
        //            {
        //                ObservableCollection<Manager> mgrList = GetManagerListFilterProject(pItem.p_ID);

        //                foreach (Manager mItem in mgrList)
        //                {
        //                    filterList.Add(mItem);
        //                }
        //            }
        //        }
        //    }

        //    return TransformManagerList(filterList);
        //}

        ///// <summary>
        ///// ManagerList를 부서 ID를 필터로 사용하여 가져온다.
        ///// </summary>
        ///// <param name="id">부서 ID</param>
        ///// <param name="itemList">데이터 소스</param>
        ///// <returns></returns>
        //public ObservableCollection<Manager> GetManagerListFilterDepartment(int id, List<Manager> itemList)
        //{
        //    ObservableCollection<Manager> filterList = new ObservableCollection<Manager>();

        //    // Department 에 속한 team List를 가져온다.
        //    ObservableCollection<Team> teamList = GetTeamListFilterDepartment(id);

        //    foreach (Team tItem in teamList)
        //    {
        //        // team에 속한 wbs list를 가져온다.
        //        ObservableCollection<WBS> wbsList = GetWBSListFilterTeam(tItem.t_ID);

        //        foreach (WBS wItem in wbsList)
        //        {
        //            // 해당 wbs에 속한 Project List를 가져온다.
        //            ObservableCollection<Project> projectList = GetProjectListFilterWBS(wItem.wbs_ID);

        //            foreach (Project pItem in projectList)
        //            {
        //                ObservableCollection<Manager> mgrList = GetManagerListFilterProject(pItem.p_ID, itemList);

        //                foreach (Manager mItem in mgrList)
        //                {
        //                    filterList.Add(mItem);
        //                }
        //            }
        //        }
        //    }

        //    return TransformManagerList(filterList);
        //}

        ///// <summary>
        ///// ManagerList를 카테고리 ID를 필터로 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <param name="id">카테고리 ID</param>
        ///// <returns></returns>
        //public ObservableCollection<Manager> GetManagerListFilterCategory(int id)
        //{
        //    ObservableCollection<Manager> itemList = _dbManager.RetrieveManagerList();
        //    ObservableCollection<Manager> filterList = new ObservableCollection<Manager>();
        //    ObservableCollection<Project> projectList = GetProjectListFilterCategory(id);

        //    foreach (Project pItem in projectList)
        //    {
        //        var query = from Manager item in itemList where item.m_P_id_fk == pItem.p_ID select item;

        //        foreach (Manager mItem in query)
        //        {
        //            filterList.Add(mItem);
        //        }
        //    }

        //    return TransformManagerList(filterList);
        //}

        ///// <summary>
        ///// ManagerList를 카테고리 ID를 필터로 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <param name="id">카테고리 ID</param>
        ///// <param name="itemList">데이터 소스</param>
        ///// <returns></returns>
        //public ObservableCollection<Manager> GetManagerListFilterCategory(int id, List<Manager> itemList)
        //{
        //    ObservableCollection<Manager> filterList = new ObservableCollection<Manager>();
        //    ObservableCollection<Project> projectList = GetProjectListFilterCategory(id);

        //    foreach (Project pItem in projectList)
        //    {
        //        var query = from Manager item in itemList where item.m_P_id_fk == pItem.p_ID select item;

        //        foreach (Manager mItem in query)
        //        {
        //            filterList.Add(mItem);
        //        }
        //    }

        //    return TransformManagerList(filterList);
        //    // return filterList;
        //}

        ///// <summary>
        ///// ManagerList를 팀 ID를 필터로 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <param name="id">Team ID</param>
        ///// <returns></returns>
        //public ObservableCollection<Manager> GetManagerListFilterTeam(int id)
        //{
        //    ObservableCollection<Manager> filterList = new ObservableCollection<Manager>();
        //    // team에 속한 wbs list를 가져온다.
        //    ObservableCollection<WBS> wbsList = GetWBSListFilterTeam(id);

        //    foreach (WBS wItem in wbsList)
        //    {
        //        // 해당 wbs에 속한 Project List를 가져온다.
        //        ObservableCollection<Project> projectList = GetProjectListFilterWBS(wItem.wbs_ID);

        //        foreach (Project pItem in projectList)
        //        {
        //            ObservableCollection<Manager> mgrList = GetManagerListFilterProject(pItem.p_ID);

        //            foreach (Manager mItem in mgrList)
        //            {
        //                filterList.Add(mItem);
        //            }
        //        }
        //    }

        //    return TransformManagerList(filterList);
        //}

        ///// <summary>
        ///// ManagerList를 Team ID를 필터로 사용하여 가져온다.
        ///// </summary>
        ///// <param name="id">Team ID</param>
        ///// <param name="itemList"> 찾고자 하는 DataSource</param>
        ///// <returns></returns>
        //public ObservableCollection<Manager> GetManagerListFilterTeam(int id, List<Manager> itemList)
        //{
        //    ObservableCollection<Manager> filterList = new ObservableCollection<Manager>();
        //    // team에 속한 wbs list를 가져온다.
        //    ObservableCollection<WBS> wbsList = GetWBSListFilterTeam(id);

        //    foreach (WBS wItem in wbsList)
        //    {
        //        // 해당 wbs에 속한 Project List를 가져온다.
        //        ObservableCollection<Project> projectList = GetProjectListFilterWBS(wItem.wbs_ID);

        //        foreach (Project pItem in projectList)
        //        {
        //            ObservableCollection<Manager> mgrList = GetManagerListFilterProject(pItem.p_ID, itemList);

        //            foreach (Manager mItem in mgrList)
        //            {
        //                filterList.Add(mItem);
        //            }
        //        }
        //    }

        //    return TransformManagerList(filterList);
        //}

        ///// <summary>
        ///// ManagerList를 프로젝트 ID를 필터로 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <param name="id">Project ID</param>
        ///// <returns></returns>
        //public ObservableCollection<Manager> GetManagerListFilterProject(int id)
        //{
        //    ObservableCollection<Manager> itemList = _dbManager.RetrieveManagerList();

        //    var query = from Manager item in itemList where item.m_P_id_fk == id select item;

        //    ObservableCollection<Manager> filterList = new ObservableCollection<Manager>();

        //    foreach (Manager mItem in query)
        //    {
        //        filterList.Add(mItem);
        //    }

        //    return TransformManagerList(filterList);
        //    // return filterList;
        //}

        ///// <summary>
        ///// ManagerList를 프로젝트 ID를 필터로 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <param name="id">프로젝트 ID</param>
        ///// <param name="itemList">찾고자하는 DataSource</param>
        ///// <returns></returns>
        //public ObservableCollection<Manager> GetManagerListFilterProject(int id, List<Manager> itemList)
        //{
        //    var query = from Manager item in itemList where item.m_P_id_fk == id select item;

        //    ObservableCollection<Manager> filterList = new ObservableCollection<Manager>();

        //    foreach (Manager mItem in query)
        //    {
        //        filterList.Add(mItem);
        //    }

        //    return TransformManagerList(filterList);
        //    // return filterList;
        //}

        ///// <summary>
        ///// ManagerList를 WBS ID를 필터로 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <param name="id">WBS ID</param>
        ///// <returns></returns>
        //public ObservableCollection<Manager> GetManagerListFilterWBS(int id)
        //{
        //    ObservableCollection<Manager> filterList = new ObservableCollection<Manager>();

        //    // 해당 wbs에 속한 Project List를 가져온다.
        //    ObservableCollection<Project> projectList = GetProjectListFilterWBS(id);

        //    foreach (Project pItem in projectList)
        //    {
        //        ObservableCollection<Manager> mgrList = GetManagerListFilterProject(pItem.p_ID);

        //        foreach (Manager mItem in mgrList)
        //        {
        //            filterList.Add(mItem);
        //        }
        //    }

        //    return TransformManagerList(filterList);
        //}

        ///// <summary>
        ///// ManagerList를 WBS의 리스트를 사용하여 가져온다. Datasource는 DB
        ///// </summary>
        ///// <param name="wbsList">WBS List</param>
        ///// <returns></returns>
        //public ObservableCollection<Manager> GetManagerListFilterWBS(List<WBS> wbsList)
        //{
        //    ObservableCollection<Manager> filterList = new ObservableCollection<Manager>();

        //    foreach (WBS wItem in wbsList)
        //    {
        //        // 해당 wbs에 속한 Project List를 가져온다.
        //        ObservableCollection<Project> projectList = GetProjectListFilterWBS(wItem.wbs_ID);

        //        foreach (Project pItem in projectList)
        //        {
        //            ObservableCollection<Manager> mgrList = GetManagerListFilterProject(pItem.p_ID);

        //            foreach (Manager mItem in mgrList)
        //            {
        //                filterList.Add(mItem);
        //            }
        //        }
        //    }

        //    return TransformManagerList(filterList);
        //}

        ///// <summary>
        ///// ManagerList를 WBS ID를 필터로 사용하여 가져온다.
        ///// </summary>
        ///// <param name="id">WBS ID</param>
        ///// <param name="itemList"> 찾고자 하는 DataSource</param>
        ///// <returns></returns>
        //public ObservableCollection<Manager> GetManagerListFilterWBS(int id, List<Manager> itemList)
        //{
        //    ObservableCollection<Manager> filterList = new ObservableCollection<Manager>();

        //    // 해당 wbs에 속한 Project List를 가져온다.
        //    ObservableCollection<Project> projectList = GetProjectListFilterWBS(id);

        //    foreach (Project pItem in projectList)
        //    {
        //        ObservableCollection<Manager> mgrList = GetManagerListFilterProject(pItem.p_ID, itemList);

        //        foreach (Manager mItem in mgrList)
        //        {
        //            filterList.Add(mItem);
        //        }
        //    }

        //    return TransformManagerList(filterList);
        //}

        ///// <summary>
        ///// ProjectList 를 CategoryID를 키로 해서 필터링 해서 가져오는 함수
        ///// </summary>
        ///// <param name="id">카테고리 아이디</param>
        ///// <returns>필터링 된 프로젝트 리스트</returns>
        //public ObservableCollection<Project> GetProjectListFilterCategory(int id)
        //{
        //    ObservableCollection<Project> itemList = _dbManager.RetrieveProjectList();

        //    var query = from Project item in itemList where item.p_C_id_fk == id select item;

        //    ObservableCollection<Project> filterList = new ObservableCollection<Project>();

        //    foreach (Project pItem in query)
        //    {
        //         filterList.Add(pItem);
        //    }
            
        //    return filterList;
        //}

        ///// <summary>
        ///// ProjectList 를 CategoryID를 키로 해서 필터링 해서 가져오는 함수
        ///// </summary>
        ///// <param name="id">카테고리 아이디</param>
        ///// <param name="itemList">찾고자하는 DataSource</param>
        ///// <returns>필터링 된 프로젝트 리스트</returns>
        //public ObservableCollection<Project> GetProjectListFilterCategory(int id, List<Project> itemList)
        //{
        //    var query = from Project item in itemList where item.p_C_id_fk == id select item;

        //    ObservableCollection<Project> filterList = new ObservableCollection<Project>();

        //    foreach (Project pItem in query)
        //    {
        //        filterList.Add(pItem);
        //    }

        //    return filterList;
        //}

        ///// <summary>
        ///// ProjectList 를 WBS ID를 키로 해서 필터링 해서 가져오는 함수
        ///// </summary>
        ///// <param name="id">WBS ID</param>
        ///// <returns>필터링 된 프로젝트 리스트</returns>
        //public ObservableCollection<Project> GetProjectListFilterWBS(int id)
        //{
        //    ObservableCollection<Project> itemList = _dbManager.RetrieveProjectList();

        //    var query = from Project item in itemList where item.p_Wbs_id_fk == id select item;

        //    ObservableCollection<Project> filterList = new ObservableCollection<Project>();

        //    foreach (Project pItem in query)
        //    {
        //        filterList.Add(pItem);
        //    }

        //    return filterList;
        //}

        ///// <summary>
        ///// ProjectList 를 WBS ID를 키로 해서 필터링 해서 가져오는 함수
        ///// </summary>
        ///// <param name="id">WBS ID</param>
        ///// <param name="itemList">찾고자하는 DataSource</param>
        ///// <returns>필터링 된 프로젝트 리스트</returns>
        //public ObservableCollection<Project> GetProjectListFilterWBS(int id, List<Project> itemList)
        //{
        //    var query = from Project item in itemList where item.p_Wbs_id_fk == id select item;

        //    ObservableCollection<Project> filterList = new ObservableCollection<Project>();

        //    foreach (Project pItem in query)
        //    {
        //        filterList.Add(pItem);
        //    }

        //    return filterList;
        //}

        ///// <summary>
        ///// ProjectList를 Team ID를 키로 해서 필터링 해서 가져오는 함수
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //public ObservableCollection<Project> GetProjectListFilterTeam(int id)
        //{
        //    ObservableCollection<Project> filterList = new ObservableCollection<Project>();
        //    ObservableCollection<Project> itemList = _dbManager.RetrieveProjectList();
            
        //    ObservableCollection<WBS> wbsList = GetWBSListFilterTeam(id);

        //    foreach (WBS wItem in wbsList)
        //    {
        //        var query = from Project item in itemList where item.p_Wbs_id_fk == wItem.wbs_ID select item;

        //        foreach (Project pItem in query)
        //        {
        //            filterList.Add(pItem);
        //        }
        //    }

        //    return filterList;
        //}

        ///// <summary>
        ///// ProjectList를 Team ID를 키로 해서 필터링 해서 가져오는 함수
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //public ObservableCollection<Project> GetProjectListFilterTeam(int id, List<Project> itemList)
        //{
        //    ObservableCollection<Project> filterList = new ObservableCollection<Project>();

        //    ObservableCollection<WBS> wbsList = GetWBSListFilterTeam(id);

        //    foreach (WBS wItem in wbsList)
        //    {
        //        var query = from Project item in itemList where item.p_Wbs_id_fk == wItem.wbs_ID select item;

        //        foreach (Project pItem in query)
        //        {
        //            filterList.Add(pItem);
        //        }
        //    }

        //    return filterList;
        //}

        ///// <summary>
        ///// Team List를 DepartMent ID를 키로 해서 필터링해서 가져오는 함수
        ///// </summary>
        ///// <param name="id">Department ID</param>
        ///// <returns></returns>
        //public ObservableCollection<Team> GetTeamListFilterDepartment(int id)
        //{
        //    ObservableCollection<Team> itemList = _dbManager.RetrieveTeamList();

        //    var query = from Team item in itemList where item.t_Dep_id_fk == id select item;

        //    ObservableCollection<Team> filterList = new ObservableCollection<Team>();

        //    foreach (Team tItem in query)
        //    {
        //        filterList.Add(tItem);
        //    }

        //    return filterList;
        //}

        ///// <summary>
        ///// TeamList를 DepartmentID를 키로해서 필터링해서 가져오는 함수
        ///// </summary>
        ///// <param name="id">Department ID</param>
        ///// <param name="itemList">데이터 소스</param>
        ///// <returns></returns>
        //public ObservableCollection<Team> GetTeamListFilterDepartment(int id, List<Team> itemList)
        //{
        //    var query = from Team item in itemList where item.t_Dep_id_fk == id select item;

        //    ObservableCollection<Team> filterList = new ObservableCollection<Team>();

        //    foreach (Team tItem in query)
        //    {
        //        filterList.Add(tItem);
        //    }

        //    return filterList;
        //}

        ///// <summary>
        ///// WBS List를 Team ID를 키로해서 필터링 해서 가져오는 함수
        ///// </summary>
        ///// <param name="id">Team ID</param>
        ///// <returns></returns>
        //public ObservableCollection<WBS> GetWBSListFilterTeam(int id)
        //{
        //    ObservableCollection<WBS> itemList = _dbManager.RetrieveWBSList();

        //    var query = from WBS item in itemList where item.wbs_T_id_fk == id select item;

        //    ObservableCollection<WBS> filterList = new ObservableCollection<WBS>();

        //    foreach (WBS wItem in query)
        //    {
        //        filterList.Add(wItem);
        //    }

        //    return filterList;
        //}

        ///// <summary>
        ///// WBS List를 Team ID를 키로해서 필터링 해서 가져오는 함수
        ///// </summary>
        ///// <param name="id">Team ID</param>
        ///// <param name="itemList">데이터 소스</param>
        ///// <returns></returns>
        //public ObservableCollection<WBS> GetWBSListFilterTeam(int id, List<WBS> itemList)
        //{
        //    var query = from WBS item in itemList where item.wbs_T_id_fk == id select item;

        //    ObservableCollection<WBS> filterList = new ObservableCollection<WBS>();

        //    foreach (WBS wItem in query)
        //    {
        //        filterList.Add(wItem);
        //    }

        //    return filterList;
        //}

        ///// <summary>
        ///// OperatorList 를 category ID를 키로 해서 필터링 해서 가져오는 함수
        ///// </summary>
        ///// <param name="id">Categoty ID</param>
        ///// <returns>필터링 된 오퍼레이터 리스트</returns>
        //public ObservableCollection<Operator> GetOperatorListFilterCategory(int cId)
        //{
        //    ObservableCollection<Operator> filterList = new ObservableCollection<Operator>();
        //    ObservableCollection<Project> projectList = GetProjectListFilterCategory(cId);

        //    // ObservableCollection<Operator> operatorList = _dbManager.RetrieveOperatorList();

        //    foreach (Project pItem in projectList)
        //    {
        //        ObservableCollection<Manager> mgrList = GetManagerListFilterProject(pItem.p_ID);

        //        foreach (Manager mItem in mgrList)
        //        {
        //            ObservableCollection<Operator> opList = GetOperatorListFilterManager(mItem.m_ID);

        //            foreach (Operator oItem in opList)
        //            {
        //                filterList.Add(oItem);
        //            }
        //        }
        //    }

        //    return TransformOperatorList(filterList);
        //}

        ///// <summary>
        ///// ResearcherList를 Team id를 키로해서 필터링하는 함수
        ///// </summary>
        ///// <param name="tid">team id</param>
        ///// <returns></returns>
        //public ObservableCollection<Researcher> GetResearcherListFilterTeam(int tid)
        //{
        //    ObservableCollection<Researcher> itemList = _dbManager.RetrieveResearcherList();

        //    var query = from Researcher item in itemList where item.r_T_id_fk == tid select item;

        //    ObservableCollection<Researcher> filterList = new ObservableCollection<Researcher>();

        //    foreach (Researcher rItem in query)
        //    {
        //        filterList.Add(rItem);
        //    }

        //    return filterList;
        //}

        //#endregion - Filter

        //#region - Util

        ///// <summary>
        /////  Combobox 에서 사용하기 위해 부서 이름으로 된 String list 만들기
        ///// </summary>
        ///// <returns></returns>
        //public List<string> GetDepartmentNameList()
        //{
        //    ObservableCollection<Department> itemList = _dbManager.RetrieveDepartmentList();
        //    var query = from Department item in itemList select item.dep_Name;
        //    return query.ToList<string>();
        //}

        //public List<string> GetTeamNameList()
        //{
        //    ObservableCollection<Team> itemList = _dbManager.RetrieveTeamList();
        //    var query = from Team item in itemList select item.t_Name;
        //    return query.ToList<string>();
        //}

        //public List<string> GetCategoryNameList()
        //{
        //    ObservableCollection<Category> itemList = _dbManager.RetrieveCategoryList();
        //    var query = from Category item in itemList select item.c_Name;
        //    return query.ToList<string>();
        //}

        //public List<string> GetProjectNameList()
        //{
        //    ObservableCollection<Project> itemList = _dbManager.RetrieveProjectList();
        //    var query = from Project item in itemList select item.p_Name;
        //    return query.ToList<string>();
        //}

        //public List<string> GetWBSNameList()
        //{
        //    ObservableCollection<WBS> itemList = _dbManager.RetrieveWBSList();
        //    var query = from WBS item in itemList select item.wbs_Name;
        //    return query.ToList<string>();
        //}

        ////새로추가
        //public List<string> GetWBSLevelList()
        //{
        //    ObservableCollection<WBS> itemList = _dbManager.RetrieveWBSList();
        //    var query = from WBS item in itemList select item.wbs_Level;
        //    return query.ToList<string>();
        //}

        //public List<string> GetResearcherNameList()
        //{
        //    ObservableCollection<Researcher> itemList = _dbManager.RetrieveResearcherList();
        //    var query = from Researcher item in itemList select item.r_Name;
        //    return query.ToList<string>();
        //}

        //public List<string> GetAuthList()
        //{
        //    List<string> strAuthorityList = new List<string>();

        //    strAuthorityList.Add("Administrator");
        //    strAuthorityList.Add("Operator");
        //    strAuthorityList.Add("Viewer");

        //    return strAuthorityList;
        //}

        //public List<string> GetRequestConditionList()
        //{
        //    List<string> strRequestConditionList = new List<string>();

        //    strRequestConditionList.Add("내자구매");
        //    strRequestConditionList.Add("외자구매");
        //    strRequestConditionList.Add("내자용역");
        //    strRequestConditionList.Add("외자용역");

        //    return strRequestConditionList;
        //}

        //public List<string> GetCurrencyList()
        //{
        //    List<string> strCurrencyList = new List<string>();

        //    strCurrencyList.Add("원");
        //    strCurrencyList.Add("USD");
        //    strCurrencyList.Add("YEN");
        //    strCurrencyList.Add("EURO");

        //    return strCurrencyList;
        //}

        //public List<string> GetStateList()
        //{
        //    List<string> strStateList = new List<string>();

        //    strStateList.Add("계약금");
        //    strStateList.Add("중도금");
        //    strStateList.Add("잔금");
        //    strStateList.Add("지불완료");

        //    return strStateList;
        //}

        //// 이게 사용될 지는 아직 미지수
        //public List<string> GetManagerNameList()
        //{
        //    ObservableCollection<Manager> itemList = _dbManager.RetrieveManagerList();
        //    var query = from Manager item in itemList select item.m_Name;
        //    return query.ToList<string>();
        //}

        //public string AuthorityToString(eResearcherAuthority auth)
        //{
        //    string authority = string.Empty;
        //    switch (auth)
        //    {
        //        case eResearcherAuthority.eOperator :
        //            authority = "Operator";
        //            break;
        //        case eResearcherAuthority.eAdministrator :
        //            authority = "Administrator";
        //            break;
        //        case eResearcherAuthority.eViewer :
        //        default:
        //            authority = "Viewer";
        //            break;
        //    }

        //    return authority;
        //}

        //public eResearcherAuthority StringToAuthority(string auth)
        //{
        //    eResearcherAuthority eAuth = eResearcherAuthority.eViewer;

        //    switch (auth)
        //    {
        //        case "Operator":
        //            eAuth = eResearcherAuthority.eOperator;
        //            break;
        //        case "Administrator":
        //            eAuth = eResearcherAuthority.eAdministrator;
        //            break;
        //        case "Viewer":
        //        default:
        //            eAuth = eResearcherAuthority.eViewer;
        //            break;
        //    }

        //    return eAuth;
        //}

        //public string RequestConditionToString(eRequestCondition condition)
        //{
        //    string strCondition = string.Empty;

        //    switch (condition)
        //    {
        //        case eRequestCondition.eExternalPurchase:
        //            strCondition = "외자구매";
        //            break;
        //        case eRequestCondition.eExternalService:
        //            strCondition = "외자용역";
        //            break;
        //        case eRequestCondition.eInternalService:
        //            strCondition = "내자용역";
        //            break;
        //        case eRequestCondition.eInternalPurchase:
        //        default:
        //            strCondition = "내자구매";
        //            break;
        //    }

        //    return strCondition;
        //}

        //public eRequestCondition StringToRequestCondition(string condition)
        //{
        //    eRequestCondition eCondition = eRequestCondition.eInternalPurchase;

        //    switch (condition)
        //    {
        //        case "외자구매":
        //            eCondition = eRequestCondition.eExternalPurchase;
        //            break;
        //        case "외자용역":
        //            eCondition = eRequestCondition.eExternalService;
        //            break;
        //        case "내자용역":
        //            eCondition = eRequestCondition.eInternalService;
        //            break;
        //        case "내자구매":
        //        default:
        //            eCondition = eRequestCondition.eInternalPurchase;
        //            break;
        //    }

        //    return eCondition;
        //}

        //public eState StringToState(string str)
        //{
        //    eState state = eState.eDownPayment;
        //    switch (str)
        //    {
        //        case "계약금" :
        //            state = eState.eDownPayment;
        //            break;
        //        case "중도금" :
        //            state = eState.eSecondPayment;
        //            break;
        //        case "잔금" :
        //            state = eState.eBalance;
        //            break;
        //        case "지불완료" :
        //            state = eState.ePayment;
        //            break;
        //    }

        //    return state;
        //}

        //public string StateToString(eState state)
        //{
        //    string strState = string.Empty;

        //    switch (state)
        //    {
        //        case eState.eDownPayment :
        //            strState = "계약금";
        //            break;
        //        case eState.eSecondPayment:
        //            strState = "중도금";
        //            break;
        //        case eState.eBalance:
        //            strState = "잔금";
        //            break;
        //        case eState.ePayment:
        //            strState = "지불완료";
        //            break;
        //    }

        //    return strState;
        //}

        //public eCurrencyType StringToCurrency(string str)
        //{
        //    eCurrencyType state = eCurrencyType.eWon;
        //    switch (str)
        //    {
        //        case "원":
        //            state = eCurrencyType.eWon;
        //            break;
        //        case "USD":
        //            state = eCurrencyType.eDollar;
        //            break;
        //        case "YEN":
        //            state = eCurrencyType.eYen;
        //            break;
        //        case "EURO":
        //            state = eCurrencyType.eEuro;
        //            break;
        //    }

        //    return state;
        //}

        //public string CurrencyToString(eCurrencyType currency)
        //{
        //    string strCurrency = string.Empty;

        //    switch (currency)
        //    {
        //        case eCurrencyType.eWon:
        //            strCurrency = "원";
        //            break;
        //        case eCurrencyType.eDollar:
        //            strCurrency = "USD";
        //            break;
        //        case eCurrencyType.eYen:
        //            strCurrency = "YEN";
        //            break;
        //        case eCurrencyType.eEuro:
        //            strCurrency = "EURO";
        //            break;
        //    }

        //    return strCurrency;
        //}

        //#endregion - Util

        //#region - SetList
        ///// <summary>
        ///// ManagerList에서 db에서의 id를 이용하여 실제 이름 등으로 표현하는것으로 변환하는 함수
        ///// </summary>
        ///// <param name="managerList"></param>
        //public ObservableCollection<Manager> TransformManagerList(ObservableCollection<Manager> managerList)
        //{
        //    // 복사 한다.
        //    ObservableCollection<Manager> cloneList = new ObservableCollection<Manager>();

        //    foreach (Manager item in managerList)
        //    {
        //        Manager cloneData = item.Clone();

        //        // Project 외래키
        //        Project project = FindProject(cloneData.m_P_id_fk);
        //        if (project != null)
        //        {
        //            cloneData.m_Project_combo = project.p_Name;
        //        }

        //        cloneList.Add(cloneData);
        //    }

        //    return cloneList;
        //}

        //public ObservableCollection<Operator> TransformOperatorList(ObservableCollection<Operator> opList)
        //{
        //    // 복사 한다.
        //    ObservableCollection<Operator> cloneList = new ObservableCollection<Operator>();

        //    foreach (Operator item in opList)
        //    {
        //        Operator cloneData = item.Clone();

        //        // Manager 에 대한 변환
        //        Manager mngr = FindManager(cloneData.o_M_id_fk);
        //        if (mngr != null)
        //        {
        //            cloneData.o_Manager_combo = mngr.m_Name;
        //        }

        //        //신청자 r_id -> r_name 변환
        //        Researcher rsc = FindResearcher(cloneData.o_R_id_fk);
        //        if (rsc != null)
        //        {
        //            cloneData.o_Researcher_combo = rsc.r_Name;
        //        }

        //        //구매 조건 변환
        //        cloneData.o_Request_condition_combo = RequestConditionToString((eRequestCondition)cloneData.o_Request_condition);

        //        // 화폐 단위 변환
        //        cloneData.o_Currency_type_combo = CurrencyToString((eCurrencyType)cloneData.o_Currency_type);

        //        // 진행 상태 변환
        //        cloneData.o_Current_status_combo = StateToString((eState)cloneData.o_Current_state);

        //        // 팀이름을 얻어와 넣어준다.
        //        Researcher rItem = FindResearcher(cloneData.o_R_id_fk);

        //        if(rItem != null)
        //        {
        //            Team tItem = FindTeam(rItem.r_T_id_fk);

        //            if(tItem != null)
        //            {
        //                cloneData.o_Team_Name = tItem.t_Name;
        //            }
        //        }

        //        cloneList.Add(cloneData);
        //    }

        //    return cloneList;
        //}

        //public ObservableCollection<WBS> TransformWBSList(ObservableCollection<WBS> wbsList)
        //{
        //    ObservableCollection<WBS> cloneList = new ObservableCollection<WBS>();

        //    foreach (WBS item in wbsList)
        //    {
        //        WBS cloneData = item.Clone();

        //        // Department 외래키
        //        Department department = FindDepartment(cloneData.wbs_Dep_id_fk);

        //        if (department != null)
        //        {
        //            cloneData.wbs_Dep_combo = department.dep_Name;
        //        }

        //        // Team 외래키
        //        Team team = FindTeam(cloneData.wbs_T_id_fk);

        //        if (team != null)
        //        {
        //            cloneData.wbs_Team_combo = team.t_Name;
        //        }

        //        cloneList.Add(cloneData);
        //    }

        //    return cloneList;
        //}
        //#endregion

        //#region - GetNewItemName
        //public string GetNewCategoryName(string name)
        //{
        //    List<Category> itemList = GetCategoryList().ToList<Category>();

        //    string newName = name;

        //    int index = 0;

        //    while (FindCategory(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewCategoryName(string name, List<Category> itemList)
        //{
        //    string newName = name;

        //    int index = 0;

        //    while (FindCategory(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewDepartmentName(string name)
        //{
        //    List<Department> itemList = GetDepartmentList().ToList<Department>();

        //    string newName = name;

        //    int index = 0;

        //    while (FindDepartment(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewDepartmentName(string name, List<Department> itemList)
        //{
        //    string newName = name;

        //    int index = 0;

        //    while (FindDepartment(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewTeamName(string name)
        //{
        //    List<Team> itemList = GetTeamList().ToList<Team>();

        //    string newName = name;

        //    int index = 0;

        //    while (FindTeam(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewTeamName(string name, List<Team> itemList)
        //{
        //    string newName = name;

        //    int index = 0;

        //    while (FindTeam(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewResearcherName(string name)
        //{
        //    List<Researcher> itemList = GetResearcherList().ToList<Researcher>();

        //    string newName = name;

        //    int index = 0;

        //    while (FindResearcher(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewResearcherName(string name, List<Researcher> itemList)
        //{
        //    string newName = name;

        //    int index = 0;

        //    while (FindResearcher(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewWBSName(string name)
        //{
        //    List<WBS> itemList = GetWBSList().ToList<WBS>();

        //    string newName = name;

        //    int index = 0;

        //    while (FindWBS(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewWBSName(string name, List<WBS> itemList)
        //{
        //    string newName = name;

        //    int index = 0;

        //    while (FindWBS(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewProjectName(string name)
        //{
        //    List<Project> itemList = GetProjectList().ToList<Project>();

        //    string newName = name;

        //    int index = 0;

        //    while (FindProject(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewProjectName(string name, List<Project> itemList)
        //{
        //    string newName = name;

        //    int index = 0;

        //    while (FindProject(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewManagerName(string name)
        //{
        //    List<Manager> itemList = GetManagerList().ToList<Manager>();

        //    string newName = name;

        //    int index = 0;

        //    while (FindManager(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewManagerName(string name, List<Manager> itemList)
        //{
        //    string newName = name;

        //    int index = 0;

        //    while (FindManager(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewOperatorName(string name)
        //{
        //    List<Operator> itemList = GetOperatorList().ToList<Operator>();

        //    string newName = name;

        //    int index = 0;

        //    while (FindOperator(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //public string GetNewOperatorName(string name, List<Operator> itemList)
        //{
        //    string newName = name;

        //    int index = 0;

        //    while (FindOperator(newName, itemList) != null)
        //    {
        //        newName = string.Format("{0} ({1})", name, index);
        //        index++;
        //    }

        //    return newName;
        //}

        //#endregion - GetNewItemName
    }
}
